<?php
namespace app\api\service;
use think\Controller;
use think\Db;

class Server extends Controller {
    static protected $err_code = 0;
    // 常见问题列表
    static public function get_faq_list($param) {
        if( !isset($param['read_type']))  return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try{
            // 获取类型为1的文章（常见问题）  阅读权限为指定用户类型  和 全部用户
            $data = db('article')->where('type', 1)->where('read_type', 'in', '9, ' . $param['read_type'])->order('id desc')->select();
            return ['data'=>$data,'code'=>200,'msg'=> 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code'=>self::$err_code, 'msg'=> $e->getMessage()];
        }
    }

    // 常见问题详情
    static public function get_faq_info($param) {
        if( !isset($param['id']))  return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try{
            $data = db('article')->where('id', $param['id'])->find();
            return ['data'=>$data,'code'=>200,'msg'=> 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code'=>self::$err_code, 'msg'=> $e->getMessage()];
        }
    }

    // 用户反馈
    static public function member_feedback($param) {
        if( !isset($param['member_id']) || !isset($param['content']) || !isset($param['type']))  return ['data'=>'','code'=>400001,'msg'=> 'FAULT'];
        try{
            $data = [
                'member_id' => $param['member_id'],
                'content' => $param['content'],
                'type' => $param['type'],
                'add_time' => time(),
            ];
            db('member_feedback')->insert($data);
            return ['code'=>200,'msg'=> 'SUCCESS'];
        } catch (\Exception $e) {
            return ['code'=>self::$err_code, 'msg'=> $e->getMessage()];
        }
    }
}





